/**
 * @purpose 发送微博
 * @author robin
 * @date 2012-03-12
 */

$(document).ready(function() {
		var hour = $("#hour")[0];
		var hv = $("#nowHour")[0].value;
		if(hv.length == 1) {
			hv = "0" + hv;
		}
		var minute = $("#minute")[0];
		var mv = $("#nowMinute")[0].value;
		if(mv.length == 1) {
			mv = "0" + mv;
		}
		for(i = 0; i < hour.options.length; i++) {
			if(hour.options[i].value == hv) {
				hour.options[i].selected = true;
				break;
			}
		}
		for(i = 0; i < minute.options.length; i++) {
			if(minute.options[i].value == mv) {
				minute.options[i].selected = true;
				break;
			}
		}
		});

function checkStatus() {
	var status = $("#status").val();
	if(status == null) {
		return false;
	}
	// trim()
	status = status.replace(/(^\s*)|(\s*$)/g, "");
	if(status == "") {
		return false;
	}
	return true;
}

function checkNextTimer() {
	var next = $("#nextTimer").val();
	var integer = /^[0-9]*[1-9][0-9]*$/;
	if(integer.test(next)) {
		if(next < 5) {
			alert("定时间隔至少5分钟!");
			return false;
		}
		return true;
	}
	alert("无效数字!");
	return false;
}

function timerSend(path) {
	if(false == checkStatus()) {
		alert("定时广播内容不能为空");
		return;
	}
	if(false == checkNextTimer()) {
		return;
	}
	form = document.forms[0];
	form.action = path + "timer/timerAction!timerSend.action";
	form.submit();
}

function nowSend(path) {
	if(false == checkStatus()) {
		alert("定时广播内容不能为空");
		return;
	}
	form = document.forms[0];
	form.action = path + "timer/timerAction!nowSend.action";
	form.submit();
}